//
//  MeHeaderView.m
//  pmmSS
//
//  Created by Mac book on 2017/9/8.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "MeHeaderView.h"

@interface MeHeaderView()

//
@property (nonatomic,strong) UIImageView * headerImageView,* userImageView,* integral_share_ImageView;
@property (nonatomic,strong) UIButton * edtiorBtn;
@property(nonatomic,strong)UILabel * nameLabel;

//
@property (nonatomic,strong) UIButton * integral_share_Btn;
@property(nonatomic,strong)UILabel * integral_share_Label,* integralNumberLabel,* shareNumberLabel;

//
@property(nonatomic,strong)UILabel * commodityorder_Label;
@property (nonatomic,strong) UIButton * order_all_Btn,*ord_four_btn;


@end


@implementation MeHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self initSubViewOne];
        [self initSubViewTwo];
        [self initSubViewThree];


    }
    return self;
}

-(void)initSubViewOne{

    WeakSelf(weakSelf);

    _headerImageView =  [[UIImageView alloc] initWithFrame:CGRectZero];

    _headerImageView.backgroundColor = RGBA(173, 167, 249, 0.8);

    [self addSubview:_headerImageView];

    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(autoScaleH(0));
        make.height.mas_equalTo(autoScaleH(139.7));
        make.width.mas_equalTo(weakSelf);
        
    }];

//-------------**************------------
    _userImageView =  [[UIImageView alloc] initWithFrame:CGRectZero];
    
    _userImageView.backgroundColor = RGBA(241, 144, 238, 0.8);
    _userImageView.clipsToBounds = YES;
    _userImageView.layer.cornerRadius = autoScaleH(30.5);

    [self addSubview:_userImageView];

    [_userImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(autoScaleH(30.9));
        make.left.mas_equalTo(autoScaleW(42.6));

        make.height.mas_equalTo(autoScaleH(61));
        make.width.mas_equalTo(autoScaleW(61));

    }];

//-------------**************------------

    _nameLabel = [ HMLabel createLabelWithText:@"啾啾" andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(18)] andTextAlignment:NSTextAlignmentLeft];

    [self addSubview:_nameLabel];

    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.userImageView);
        make.left.mas_equalTo(autoScaleW(153.5));
        make.width.mas_equalTo(autoScaleW(100));
        make.height.mas_equalTo(autoScaleH(16));

    }];

    //-------------**************------------

    _edtiorBtn = [HMButton createButtonWithTitle:@"" andTitleColor:[UIColor yellowColor] andBgColor:[UIColor whiteColor] andImage:[UIImage imageNamed:@"icon_comment"] andBgImage:nil andSelecter:@selector(click:) andTarget:self andTag:101];
    _edtiorBtn.clipsToBounds = YES;
    _edtiorBtn.layer.cornerRadius = autoScaleH(17.9);

    [self addSubview:_edtiorBtn];

    [_edtiorBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(autoScaleH(53.5));
        make.right.mas_equalTo(autoScaleW(-14.6));
        make.width.mas_equalTo(autoScaleW(34.8));
        make.height.mas_equalTo(autoScaleH(34.8));
        
    }];


}

-(void)initSubViewTwo{


    WeakSelf(weakSelf);

    for (int i = 0; i < 2; i++) {

        _integral_share_Btn = [HMButton createButtonWithTitle:@"" andTitleColor:nil andBgColor:nil andImage:[UIImage imageNamed:@""] andBgImage:nil andSelecter:@selector(click:) andTarget:self andTag:102 + i];

        [self addSubview:_integral_share_Btn];



         //-------------**************------------

        _integral_share_ImageView =  [[UIImageView alloc] init];

        _integral_share_ImageView.backgroundColor = RGBA(253, 138, 40, 1);

        [self.integral_share_Btn addSubview:_integral_share_ImageView];

        //-------------**************------------
        _integral_share_Label = [ HMLabel createLabelWithText:@"" andTextColor:RGBA(252, 26, 55, 1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(20)] andTextAlignment:NSTextAlignmentLeft];

        [self addSubview:_integral_share_Label];

       //-------------**************------------

        if (i == 0) {

            _integral_share_Label.text = @"积分";

            [_integral_share_Btn mas_makeConstraints:^(MASConstraintMaker *make) {

                make.left.mas_equalTo(0);
                make.top.mas_equalTo(weakSelf.headerImageView.mas_bottom).offset(0);
                make.width.mas_equalTo((weakSelf.frame.size.width-autoScaleW(20))/2);
                make.height.mas_equalTo(autoScaleH(92));
                
            }];

        }else{

            [_integral_share_Btn mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.headerImageView.mas_bottom).offset(0);
                make.right.mas_equalTo(0);
                make.width.mas_equalTo((weakSelf.frame.size.width-autoScaleW(20))/2);
                make.height.mas_equalTo(autoScaleH(92));
                
            }];

            _integral_share_Label.text = @"股份";

        }

        //-------------**************------------


        [_integral_share_ImageView mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(weakSelf.integral_share_Btn).offset(autoScaleW(49.5 ));
            make.top.mas_equalTo(weakSelf.integral_share_Btn).offset(autoScaleH(13));
            make.height.mas_equalTo(autoScaleW(20));
            make.width.mas_equalTo(autoScaleH(20));
            
        }];

         //-------------**************------------

        [_integral_share_Label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(weakSelf.integral_share_Btn).offset(autoScaleH(14));
            make.left.mas_equalTo(weakSelf.integral_share_ImageView.mas_right).offset(autoScaleW(12.5));
            make.width.mas_equalTo(autoScaleW(41));
            make.height.mas_equalTo(autoScaleH(20));
            
        }];


        if (i == 0) {
            _integralNumberLabel = [ HMLabel createLabelWithText:@"5566" andTextColor:RGBA(252, 26, 55, 1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(24)] andTextAlignment:NSTextAlignmentLeft];

            [self addSubview:_integralNumberLabel];

            [_integralNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.headerImageView.mas_bottom).offset(autoScaleH(46.7));
                make.left.mas_equalTo(weakSelf.integral_share_ImageView.mas_right).offset(autoScaleW(-10));
                make.width.mas_equalTo(autoScaleW(70));
                make.height.mas_equalTo(autoScaleH(24));
                
            }];

        }else{

            _shareNumberLabel = [ HMLabel createLabelWithText:@"8866" andTextColor:RGBA(252, 26, 55, 1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(24)] andTextAlignment:NSTextAlignmentLeft];

            [self addSubview:_shareNumberLabel];

            [_shareNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.headerImageView.mas_bottom).offset(autoScaleH(46.7));
                make.left.mas_equalTo(weakSelf.integral_share_ImageView.mas_right).offset(autoScaleW(-10));
                make.width.mas_equalTo(autoScaleW(70));
                make.height.mas_equalTo(autoScaleH(24));
                
            }];

        }

    }
    //for  end
    //-------------**************------------

    UIView *lineview =[[UIView alloc]init];
    lineview.backgroundColor = RGB(239, 239, 239);
    [self addSubview:lineview];

    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(weakSelf);
        make.top.mas_equalTo(weakSelf.headerImageView.mas_bottom).offset(autoScaleH(14.7));

        make.width.mas_equalTo(1);
        make.height.mas_equalTo(autoScaleH(62.6));


    }];

    //-------------**************------------

}

-(void)initSubViewThree{


    WeakSelf(weakSelf);

    for (int i = 0 ; i < 3 ; i++) {

        UIView *lineview =[[UIView alloc]init];
        lineview.backgroundColor = RGB(239, 239, 239);
        [self addSubview:lineview];

        if (i == 0) {

            [lineview mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(0);
                make.width.mas_equalTo(weakSelf);
                make.height.mas_equalTo(autoScaleH(0.5));
                
            }];
        }else if (i == 1){
            [lineview mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(autoScaleH(44.8));
                make.width.mas_equalTo(weakSelf);
                make.height.mas_equalTo(autoScaleH(0.5));

            }];

        }else{
            [lineview mas_makeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(autoScaleH(116.8));
                make.width.mas_equalTo(weakSelf);
                make.height.mas_equalTo(autoScaleH(9.8));
                
            }];

        }

    }

    //-------------**************------------

    _nameLabel = [ HMLabel createLabelWithText:@"商城订单" andTextColor:[UIColor blackColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(16)] andTextAlignment:NSTextAlignmentCenter];

    [self addSubview:_nameLabel];

    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(autoScaleH(11.1));
        make.left.mas_equalTo(autoScaleW(8.9));
        make.width.mas_equalTo(autoScaleW(66));
        make.height.mas_equalTo(autoScaleH(19));
        
    }];

    //-------------**************------------

    _order_all_Btn = [HMButton createButtonWithTitle:@"查看全部商城订单" andTitleColor:[UIColor blackColor] andBgColor:nil andImage:[UIImage imageNamed:@""] andBgImage:nil andSelecter:@selector(click:) andTarget:self andTag:104];
    _order_all_Btn.titleLabel.font = [UIFont fontWithName:default_fontname size:autoScaleW(14)];

    [self addSubview:_order_all_Btn];

    [_order_all_Btn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(autoScaleH(12.6));
        make.right.mas_equalTo(autoScaleW(-28.4));
        make.width.mas_equalTo(autoScaleW(115));
        make.height.mas_equalTo(autoScaleH(17));
        
    }];

    //-------------**************------------

    NSArray *itemsArray = @[@"待付款",@"待发货",@"待收货",@"待评价"];

    for (int i = 0 ; i < 4 ; i++) {

        _ord_four_btn = [HMButton createButtonWithTitle:itemsArray[i] andTitleColor:[UIColor blackColor] andBgColor:nil andImage:[UIImage imageNamed:@""] andBgImage:nil andSelecter:@selector(click:) andTarget:self andTag:105 + i];

        _ord_four_btn.titleLabel.font = [UIFont fontWithName:default_fontname size:autoScaleW(14)];

      //  [_order_all_Btn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

        [_ord_four_btn setTitleEdgeInsets:UIEdgeInsetsMake(autoScaleH(42), 0, 13.2, 0)] ;

        [self addSubview:_ord_four_btn];

        [_ord_four_btn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(weakSelf.integral_share_Btn.mas_bottom).offset(autoScaleH(45.3));
            make.left.mas_equalTo((weakSelf.frame.size.width/4)*i);
            make.width.mas_equalTo(weakSelf.frame.size.width/4);
            make.height.mas_equalTo(autoScaleH(71.7));
            
        }];

    };


}
-(void)click:(UIButton *)button{

    [self.delegate clickButtonTag:button.tag];

    NSLog(@"tag------%ld",(long)button.tag);


}

@end
